package cn.topevery.garden.dal.dao.impl;

import cn.topevery.garden.dal.dao.StoreInfoDao;
import cn.topevery.garden.entity.po.StoreInfo;
import cn.topevery.garden.entity.query.StoreInfoQuery;
import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import hw.topevery.framework.entity.DbCsp;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 
 *
 * @author code-generate
 * @date 2021-08-30
 */
@Repository
public class StoreInfoDaoImpl extends BaseDaoImpl<StoreInfo> implements StoreInfoDao {
    @Override
    public <P extends DbCsp> List<StoreInfo> getSearch(P para) {
        return null;
    }

    

    @Override
    public DataPager<StoreInfo> listPage(StoreInfoQuery query) {
        String table = "t_store_info tsi";

        String columns = "tsi.*";
        int pageIndex = query.pageIndex-1;
        int pageSize = query.pageSize;

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("tsi.c_db_create_date desc");
        sqlQueryMate
                .where(true, "tsi.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(StringUtils.isNotEmpty(query.getName()), "tsi.c_name", ScriptConditionEnum.Like, query.getName())
                .where(StringUtils.isNotEmpty(query.getTypeName()), "tsi.c_type_name", ScriptConditionEnum.Like, query.getTypeName())
        ;

        return getDataPager(sqlQueryMate, pageSize,pageIndex, StoreInfo.class);
    }

    /**
     * 描述 检查是否已经存在.
     *
     * @param fieldName 字段名
     * @param value     字段值
     * @return the boolean （true已存在，false不存在）
     * @author wenzhao.lin
     * @created 2021 -08-19 09:23:47 Is exit boolean.
     */
    @Override
    public boolean isExit(String fieldName, String value) {
        String table = "t_store_info";
        String columns = fieldName;
        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns);
        sqlQueryMate
                .where(true, "c_db_status", ScriptConditionEnum.Eq, 0)
                .where(true, fieldName, ScriptConditionEnum.Eq, value)
        ;
        List<StoreInfo> list = selectList(sqlQueryMate,StoreInfo.class);
        if(list != null && list.size()>0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public List<StoreInfo> getStoreList(String fieldName, String value) {
        String table = "t_store_info";
        String columns = "*";
        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns);
        sqlQueryMate
                .where(true, "c_db_status", ScriptConditionEnum.Eq, 0)
                .where(true, fieldName, ScriptConditionEnum.Eq, value)
        ;
        List<StoreInfo> list = selectList(sqlQueryMate,StoreInfo.class);
        return list;
    }
}
